<!-- 首页 -->
<template>
  <view class="content">
    <Header />
    <!-- APP介绍 -->
    <view class="app-desc" v-if="bannerList.length > 0">
      <swiper class="swiper-container" autoplay :interval="3000" circular layout-type="stackLeft">
        <swiper-item
          v-for="(item, index) in bannerList"
          :key="index"
          @click="openPage('/pages/information/webpage?url=' + item.linkUrl)"
        >
          <view
            class="bg-cover swiper-image"
            :style="{ backgroundImage: 'url(' + item.picture + ')' }"
          ></view>
        </swiper-item>
      </swiper>
    </view>
    <view class="grid">
      <HomeCategory />
      <!--列表-->
      <ActivityList :list="activityList" custom-style="home" />
      <!--底部缺省-->
      <HomeDefault :logo-info="bottomLogo" />
    </view>
    <FooterBar />
    <AdvertisePopup
      v-model:show-popup="showPopup"
      @advertiseClick="openPage"
      :list="advertiseList"
    />
    <!-- contact -->
	<Contact/>
  </view>
</template>

<script setup>
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { onMounted, ref } from "vue";
import { useStore } from "vuex";
import Header from "@/components/Header/HomeHeader.vue";
import FooterBar from "@/components/FooterBar/index.vue";
import HomeCategory from "../components/HomeCategory.vue";
import ActivityList from "@/components/List/Activity.vue";
import HomeDefault from "@/components/Tip/HomeDefault.vue";
import AdvertisePopup from "@/components/Popup/AdvertisePopup.vue";
import Contact from "@/components/Tags/Contact.vue"
import { getHomeActList, getHomePageConfig } from "@/server/api.js";
import { openPage } from "@/util/index.js";

const store = useStore();

const activityList = ref([]);
let currentPage = ref(1);
let bottomLogo = ref({}); // 底部logoo
let bannerList = ref([]); // 顶部宣传
let showPopup = ref(false);
let advertiseList = ref([]);
let isLoad = ref(true);

// get list
const getList = () => {
  getHomeActList({
    current: currentPage.value,
    size: 10,
  }).then(res => {
    if (currentPage.value == 1) {
      activityList.value = res.data.records;
    } else {
      activityList.value = [...activityList.value, ...res.data.records];
    }
    currentPage.value = currentPage.value + 1;
    isLoad.value = !Boolean(res.data.records.length == 0);
  });
};

const getConfig = (type, status) => {
  getHomePageConfig({
    configStatus: status,
    type: type,
  }).then(res => {
    switch (type) {
      case 1: // 底部Logo
        bottomLogo.value = res.data.configRespDTOList[0];
        break;
      case 2: // 顶部宣传图
        bannerList.value = res.data.configRespDTOList;
        break;
      case 3: // 弹窗广告
        let advertise = uni.getStorageSync("advertise");
        showPopup.value = res.data.configRespDTOList.length > 0 && !advertise;
        advertiseList.value = res.data.configRespDTOList;
        break;
    }
  });
};

getConfig(1, 0);
getConfig(2, 2);
getConfig(3, 2);

onReachBottom(() => {
  // isLoad.value ? getList(): null
});

onLoad(() => {
  // currentPage.value = 1;
  // isLoad.value = true;
  getList();
});



</script>

<style lang="scss" scoped>
.content {
  padding: 40rpx 20rpx 80rpx;
}
.app-desc {
  height: 1146rpx;
  .swiper-container {
    height: 100%;
    .swiper-image {
      height: 100%;
    }
  }
}
.contact {
  position: fixed;
  width: 84rpx;
  height: 84rpx;
  bottom: 228rpx;
  right: 46rpx;
  z-index: 9999;
  image {
    width: 84rpx;
  }
  button {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    filter: alpha(opacity=0);
  }
}
</style>
